import Koa from "koa";
import cors from "koa2-cors";
import logger from "./middlewares/logger.js";
import compress from "./middlewares/compress.js";
import bodyParser from "./middlewares/bodyParser.js";
import staticPath from "./middlewares/static.js";
import router from "./routes/index.js";
import koajsJwt from "koa-jwt";
import { jwtConfig } from "./database/config.js";
import checkBlackToken from "./middlewares/checkBlackToken.js";

const app = new Koa();

app.use(cors({ origin: '*', credentials: true }));
app.use(compress());
app.use(logger());
app.use(bodyParser());
app.use(staticPath());
const { secret } = jwtConfig;
app.use(koajsJwt({ secret }).unless({ path: [/^\/test/, /^\/users\/login/] }));
app.use(checkBlackToken);
app.use(router.routes()).use(router.allowedMethods());

export default app;
